/*
 * @Author: aei
 * @Date: 2022-08-18 21:44:01
 * @LastEditors: aei
 * @LastEditTime: 2022-08-18 22:54:57
 * @Description: 
 */
import {record} from 'rrweb'
// import RrwebPlayer from 'rrweb-player';
// import 'rrweb-player/dist/style.css';

let myEvents = [];
let errorIds= [] 

record({
  emit(event, isCheckout) {
    if(isCheckout)  {
      errorIds.forEach(id => {
        fetch(new Request('', {
          method: 'post',
          headers: {'Content-Type': 'application/json;charset=utf-8'},
          body: JSON.stringify({
            id,
            record: myEvents
          })
        })).then(null, (err) => {
          console.error(err)
        })
      })
      errorIds = []
      myEvents = []
    }
    myEvents.push(event);
  },
  checkoutEveryNms: 5 * 60 * 1000,
},);

export default {
  jsError(id) {
    errorIds.push(id)
  }
}


// export const replay = function() {
//   replayer = new RrwebPlayer({
//     target: document.getElementById('replayer'),
//     props: {
//       events: errorRecords,
//       width: 500,
//       height: 500,
//       showWarning: false,
//       tags: {
//         error: 'red'
//       }
//     }
//   })
//   replayer.play();
// }

